package com.bsj.media.media.packageFlv;



import com.bsj.media.media.ParserVideoData;
import lombok.extern.slf4j.Slf4j;

import java.nio.ByteBuffer;

/**
 * @Description 音频flv处理
 * @Date 2022/10/25 14:49
 **/
@Slf4j
public class AudioFlvHandler extends FlvTypeHandler{

    private CacheParams cacheParamsNow; // 缓存参数

    public AudioFlvHandler(CacheParams cacheParams) {
        super((byte) 0x04);
        cacheParamsNow = cacheParams;
    }


    @Override
    public boolean preJudgement(byte[] fdBody) {
        // 判断是否是音频 3:表示音频
        if (fdBody[1] != 0x03) {
            return false;
        }
        super.audioType = ParserVideoData.getAudioType(fdBody);
        // 音频采样大小
        super.audioSampleRate = super.audioType == 3 ? 16000 : 41000;
        log.info("开始打包, uri:" +  ", 采样率:" + super.audioSampleRate);
        return true;
    }



    @Override
    public void setFristMediaTag(byte[] fdBody, ByteBuffer dst) {
        // 1、音频Tag[0]打包
        if (dst.position() != 0) {
            // 表示视频打包成功
            super.aacAudioFristTagFlv(dst);
        }
    }

    @Override
    public boolean packVideoFlag() {
        return false;
    }

    @Override
    public boolean packAudioFlag() {
        return true;
    }
}
